package com.pi.stroop.dao.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.pi.comm.mapper.BaseMapper;

import com.pi.stroop.dao.entity.StroopTaskRecordEntity;

/**
 * 表stroop_task_record的mapper类
 *
 */
public interface StroopTaskRecordMapper extends BaseMapper<StroopTaskRecordEntity, Long>{

  @Select({"<script>",
    "SELECT id, create_date, update_date, version, diagnosis_id, task_id, task_user_id, "
    + "task_start_time, task_result_param, task_correct_count, task_error_count,"
    + "task_mis_count, task_total_time FROM stroop_task_record WHERE diagnosis_id IN",
    "<if test='list != null and list.size()>0'>",
    " <foreach item='item' index='index' collection='list' ",
    "open='(' separator=',' close=')'>#{item}</foreach>",
    "</if>",
    "</script>"})
  public List<StroopTaskRecordEntity> queryTaskRecordByDiagnosisIds(@Param("list")List<Long> diagnosisIds);
  
  @Update({"<script>",
    "UPDATE stroop_task_record` SET VERSION = VERSION + 1, diagnosis_id= #{diagnosisId} WHERE id in ",
    "<if test='list != null and list.size()>0'>",
    " <foreach item='item' index='index' collection='list' ",
    "open='(' separator=',' close=')'>#{item}</foreach>",
    "</if>",
    "</script>"})
  public void updateTaskDiagnosiIdByIds(
      @Param("list")List<Long> ids, @Param("diagnosisId") Long diagnosisId);

  @Update({"<script>",
    "update stroop_task_record set version=version+1, update_date=now() ,",
    "diagnosis_id=#{diagnosisId} where ID IN ",
    "<if test='list != null and list.size()>0'>",
    " <foreach item='item' index='index' collection='list' ",
    "open='(' separator=',' close=')'>#{item}</foreach>",
    "</if>  AND VERSION=#{version}",
    "</script>"})
  public int updateByIds(
      @Param("list") List<Long> ids, @Param("diagnosisId") Long diagnosisId,
      @Param("version") Long version);
}